/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package bookleprojeto;

import javax.swing.JComboBox;
import javax.swing.JOptionPane;

/**
 *
 * @author admin
 */
public class TelaPesquisar extends javax.swing.JInternalFrame {

    TelaLogin telalogin = new TelaLogin();

    private static String resNomecurso = null;
    private static String resNomedisciplina = null;
    private static String resNomedisciplina02 = null;
    private static String resNomedisciplina03 = null;
    /**
     * Creates new form TelaPesquisar
     */
    public TelaPesquisar() {
        initComponents();
    }

    public void preencheComboBox(String selectQuery, String nomecoluna, JComboBox itemcombobox) {
        //System.out.println(selectQuery);
        try {
            ConexaoMysql conectmysql = new ConexaoMysql();
            conectmysql.abrirConexao();
            conectmysql.statement = conectmysql.conexao.createStatement();

            conectmysql.resultset = conectmysql.statement.executeQuery(selectQuery);

            itemcombobox.removeAllItems();

            while (conectmysql.resultset.next()) {
                itemcombobox.addItem(conectmysql.resultset.getString(nomecoluna));
            }

        } catch (Exception erro) {
            System.out.println("Erro: " + erro);

        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jdesktoppanelPesquisar = new javax.swing.JDesktopPane();
        labelTitulo = new javax.swing.JLabel();
        buttonRemoveDisc02 = new javax.swing.JButton();
        buttonRemoveDisc03 = new javax.swing.JButton();
        jcomboboxCurso = new javax.swing.JComboBox();
        buttonAddDisc03 = new javax.swing.JButton();
        jcomboboxDisciplina03 = new javax.swing.JComboBox();
        labelDisciplina = new javax.swing.JLabel();
        labelCurso = new javax.swing.JLabel();
        jcomboboxDisciplina02 = new javax.swing.JComboBox();
        buttonAddDisc02 = new javax.swing.JButton();
        jbuttonCancelar = new javax.swing.JButton();
        jcomboboxDisciplina = new javax.swing.JComboBox();
        jbuttonAcessar = new javax.swing.JButton();

        setClosable(true);
        setPreferredSize(new java.awt.Dimension(1277, 611));

        jdesktoppanelPesquisar.setBackground(new java.awt.Color(204, 204, 204));
        jdesktoppanelPesquisar.setPreferredSize(new java.awt.Dimension(1289, 577));

        labelTitulo.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        labelTitulo.setText("Bookle Sistema Acadêmico");

        buttonRemoveDisc02.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bookleprojeto/imagensBookle/block.png"))); // NOI18N
        buttonRemoveDisc02.setText("Remover");
        buttonRemoveDisc02.setEnabled(false);
        buttonRemoveDisc02.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRemoveDisc02ActionPerformed(evt);
            }
        });

        buttonRemoveDisc03.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bookleprojeto/imagensBookle/block.png"))); // NOI18N
        buttonRemoveDisc03.setText("Remover");
        buttonRemoveDisc03.setEnabled(false);
        buttonRemoveDisc03.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRemoveDisc03ActionPerformed(evt);
            }
        });

        jcomboboxCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        preencheComboBox("select * from tbcurso", "nomecurso", jcomboboxCurso);
        jcomboboxCurso.setSelectedIndex(-1);
        jcomboboxCurso.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jcomboboxCursoMouseClicked(evt);
            }
        });
        jcomboboxCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcomboboxCursoActionPerformed(evt);
            }
        });

        buttonAddDisc03.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bookleprojeto/imagensBookle/add.png"))); // NOI18N
        buttonAddDisc03.setText("Adicionar");
        buttonAddDisc03.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAddDisc03ActionPerformed(evt);
            }
        });

        jcomboboxDisciplina03.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
        jcomboboxDisciplina03.setModel(new javax.swing.DefaultComboBoxModel());
        jcomboboxDisciplina03.setSelectedIndex(-1);
        jcomboboxDisciplina03.setEnabled(false);

        labelDisciplina.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        labelDisciplina.setText("Disciplina(s)");

        labelCurso.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        labelCurso.setText("Curso");

        jcomboboxDisciplina02.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
        jcomboboxDisciplina02.setModel(new javax.swing.DefaultComboBoxModel());
        jcomboboxDisciplina02.setSelectedIndex(-1);
        jcomboboxDisciplina02.setEnabled(false);

        buttonAddDisc02.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bookleprojeto/imagensBookle/add.png"))); // NOI18N
        buttonAddDisc02.setText("Adicionar");
        buttonAddDisc02.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAddDisc02ActionPerformed(evt);
            }
        });

        jbuttonCancelar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jbuttonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bookleprojeto/imagensBookle/delete.png"))); // NOI18N
        jbuttonCancelar.setText("Sair");
        jbuttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbuttonCancelarActionPerformed(evt);
            }
        });

        jcomboboxDisciplina.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jcomboboxDisciplina.setModel(new javax.swing.DefaultComboBoxModel());
        jcomboboxDisciplina.setEnabled(false);

        jbuttonAcessar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jbuttonAcessar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bookleprojeto/imagensBookle/search.png"))); // NOI18N
        jbuttonAcessar.setText("Pesquisar");
        jbuttonAcessar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbuttonAcessarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jdesktoppanelPesquisarLayout = new javax.swing.GroupLayout(jdesktoppanelPesquisar);
        jdesktoppanelPesquisar.setLayout(jdesktoppanelPesquisarLayout);
        jdesktoppanelPesquisarLayout.setHorizontalGroup(
            jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdesktoppanelPesquisarLayout.createSequentialGroup()
                .addContainerGap(408, Short.MAX_VALUE)
                .addGroup(jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdesktoppanelPesquisarLayout.createSequentialGroup()
                        .addGroup(jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labelCurso)
                            .addComponent(jcomboboxDisciplina, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jcomboboxDisciplina02, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(labelDisciplina)
                            .addGroup(jdesktoppanelPesquisarLayout.createSequentialGroup()
                                .addComponent(jbuttonAcessar, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(35, 35, 35)
                                .addComponent(jbuttonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jcomboboxDisciplina03, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcomboboxCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(buttonAddDisc02, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(buttonAddDisc03, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(buttonRemoveDisc02, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(buttonRemoveDisc03, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(227, 227, 227))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdesktoppanelPesquisarLayout.createSequentialGroup()
                        .addComponent(labelTitulo)
                        .addGap(379, 379, 379))))
        );
        jdesktoppanelPesquisarLayout.setVerticalGroup(
            jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdesktoppanelPesquisarLayout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(labelTitulo)
                .addGap(31, 31, 31)
                .addComponent(labelCurso)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcomboboxCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21)
                .addComponent(labelDisciplina)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcomboboxDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jcomboboxDisciplina02, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(buttonAddDisc02, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(buttonRemoveDisc02, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buttonRemoveDisc03, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcomboboxDisciplina03, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonAddDisc03, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 60, Short.MAX_VALUE)
                .addGroup(jdesktoppanelPesquisarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbuttonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbuttonAcessar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(54, 54, 54))
        );
        jdesktoppanelPesquisar.setLayer(labelTitulo, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(buttonRemoveDisc02, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(buttonRemoveDisc03, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(jcomboboxCurso, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(buttonAddDisc03, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(jcomboboxDisciplina03, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(labelDisciplina, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(labelCurso, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(jcomboboxDisciplina02, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(buttonAddDisc02, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(jbuttonCancelar, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(jcomboboxDisciplina, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jdesktoppanelPesquisar.setLayer(jbuttonAcessar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jdesktoppanelPesquisar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1273, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jdesktoppanelPesquisar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        setBounds(0, 0, 1289, 611);
    }// </editor-fold>//GEN-END:initComponents

    private void jcomboboxCursoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jcomboboxCursoMouseClicked

    }//GEN-LAST:event_jcomboboxCursoMouseClicked

    private void jcomboboxCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcomboboxCursoActionPerformed
        // Ao clicar ele seta como editavel
        jcomboboxDisciplina.setEnabled(true);
        // Setando conteudo comboboxindex na variavel
        setResNomecurso((String) jcomboboxCurso.getSelectedItem());
        setResNomedisciplina((String) jcomboboxDisciplina.getSelectedItem());

        // chamando metodo pra preencher comboboxDisciplina
        preencheComboBox("SELECT * FROM tbdisciplina INNER JOIN tbcurso ON tbdisciplina.codcurso = tbcurso.codcurso"
            + " AND tbcurso.nomecurso LIKE '" + getResNomecurso() + "'", "nomedisciplina", jcomboboxDisciplina);
        jcomboboxDisciplina.setSelectedIndex(-1);

        // chamando metodo pra peencher comboboxDisciplina02
        preencheComboBox("SELECT * FROM tbdisciplina INNER JOIN tbcurso ON tbdisciplina.codcurso = tbcurso.codcurso"
            + " AND tbcurso.nomecurso LIKE '" + getResNomecurso() + "'", "nomedisciplina", jcomboboxDisciplina02);
        jcomboboxDisciplina02.setSelectedIndex(-1);

        // chamando metodo pra peencher comboboxDisciplina03
        preencheComboBox("SELECT * FROM tbdisciplina INNER JOIN tbcurso ON tbdisciplina.codcurso = tbcurso.codcurso"
            + " AND tbcurso.nomecurso LIKE '" + getResNomecurso() + "'", "nomedisciplina", jcomboboxDisciplina03);
        jcomboboxDisciplina03.setSelectedIndex(-1);
    }//GEN-LAST:event_jcomboboxCursoActionPerformed

    private void buttonAddDisc02ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddDisc02ActionPerformed
        jcomboboxDisciplina02.setEnabled(true);
        buttonRemoveDisc02.setEnabled(true);
        buttonAddDisc02.setEnabled(false);

    }//GEN-LAST:event_buttonAddDisc02ActionPerformed

    private void buttonRemoveDisc02ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveDisc02ActionPerformed
        jcomboboxDisciplina02.setEnabled(false);
        jcomboboxDisciplina02.setSelectedIndex(-1);
        resNomedisciplina02 = null;
        buttonAddDisc02.setEnabled(true);
        buttonRemoveDisc02.setEnabled(false);
    }//GEN-LAST:event_buttonRemoveDisc02ActionPerformed

    private void buttonRemoveDisc03ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveDisc03ActionPerformed
        jcomboboxDisciplina03.setEnabled(false);
        jcomboboxDisciplina03.setSelectedIndex(-1);
        resNomedisciplina03 = null;
        buttonAddDisc03.setEnabled(true);
        buttonRemoveDisc03.setEnabled(false);
    }//GEN-LAST:event_buttonRemoveDisc03ActionPerformed

    private void buttonAddDisc03ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddDisc03ActionPerformed
        jcomboboxDisciplina03.setEnabled(true);
        buttonRemoveDisc03.setEnabled(true);
        buttonAddDisc03.setEnabled(false);
    }//GEN-LAST:event_buttonAddDisc03ActionPerformed

    private void jbuttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbuttonCancelarActionPerformed
       dispose();
    }//GEN-LAST:event_jbuttonCancelarActionPerformed

    private void jbuttonAcessarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbuttonAcessarActionPerformed
        
        setResNomecurso((String) jcomboboxCurso.getSelectedItem());

        setResNomedisciplina((String) jcomboboxDisciplina.getSelectedItem());

        setResNomedisciplina02((String) jcomboboxDisciplina02.getSelectedItem());

        setResNomedisciplina03((String) jcomboboxDisciplina03.getSelectedItem());

        if (getResNomecurso() == null || getResNomedisciplina() == null && getResNomedisciplina02() == null && getResNomedisciplina03() == null) {
            JOptionPane.showMessageDialog(null, "O Curso deve ser selecionado, juntamente com a disciplina!", "Aviso", JOptionPane.ERROR_MESSAGE);
        } else {

            TelaLivrosSugeridos telalivrossugeridos = new TelaLivrosSugeridos();
            jdesktoppanelPesquisar.add(telalivrossugeridos);
            telalivrossugeridos.setVisible(true);

        }
    }//GEN-LAST:event_jbuttonAcessarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonAddDisc02;
    private javax.swing.JButton buttonAddDisc03;
    private javax.swing.JButton buttonRemoveDisc02;
    private javax.swing.JButton buttonRemoveDisc03;
    private javax.swing.JButton jbuttonAcessar;
    private javax.swing.JButton jbuttonCancelar;
    private javax.swing.JComboBox jcomboboxCurso;
    private javax.swing.JComboBox jcomboboxDisciplina;
    private javax.swing.JComboBox jcomboboxDisciplina02;
    private javax.swing.JComboBox jcomboboxDisciplina03;
    private javax.swing.JDesktopPane jdesktoppanelPesquisar;
    private javax.swing.JLabel labelCurso;
    private javax.swing.JLabel labelDisciplina;
    private javax.swing.JLabel labelTitulo;
    // End of variables declaration//GEN-END:variables
/**
     * @return the resNomecurso
     */
    public String getResNomecurso() {
        return resNomecurso;
    }

    public void setResNomecurso(String resNomecurso) {
        this.resNomecurso = resNomecurso;
    }

    public String getResNomedisciplina() {
        return resNomedisciplina;
    }

    public void setResNomedisciplina(String resNomedisciplina) {
        this.resNomedisciplina = resNomedisciplina;
    }

    /**
     * @return the resNomedisciplina02
     */
    public static String getResNomedisciplina02() {
        return resNomedisciplina02;
    }

    /**
     * @param aResNomedisciplina02 the resNomedisciplina02 to set
     */
    public static void setResNomedisciplina02(String aResNomedisciplina02) {
        resNomedisciplina02 = aResNomedisciplina02;
    }

    /**
     * @return the resNomedisciplina03
     */
    public static String getResNomedisciplina03() {
        return resNomedisciplina03;
    }

    /**
     * @param aResNomedisciplina03 the resNomedisciplina03 to set
     */
    public static void setResNomedisciplina03(String aResNomedisciplina03) {
        resNomedisciplina03 = aResNomedisciplina03;
    }
    
}
